import httpFetch from 'share/httpFetch';
import configureStore from 'stores';
import { setProfile } from 'actions/login';
import errorMessage from 'share/errorMessage';

export default {

  // 获取商务卡开通用户的列表
  getCMBCAccount() {
    return httpFetch.unsafe.get('/api/tenant/bankcard/accounts/CMBC');
  },

  /**
   * 商务卡启用／禁用
   * @param type 商务卡类型：CMBC
   * @param operation 1启用，0禁用
   */
  updateBankcardStatus(type, operation) {
    return httpFetch.put(`/api/tenant/bankcard/status/${type}/${operation}`);
  },

  // 更新商务卡账户列表
  updateCMBCService(params) {
    return httpFetch.post('/api/tenant/bankcard/account/CMBC', params);
  },

  // 更新商务卡消费记录属性
  updateCMBCConsumeType(params) {
    return httpFetch.post('/api/function/profiles/setProfile', params);
  },

  getProfiles() {
    return httpFetch.get('/api/function/profiles')
      .then((response) => configureStore.store.dispatch(setProfile(response.data)));
  },

  // 获取租户模式下商务卡开通状态
  getBankcardStatus(type) {
    return httpFetch.get(`/api/tenant/bankcard/status/${type}`);
  },
  // 获取是否能够开启自动创建借款单
  isAutoCreate() {
    return httpFetch.get('/api/tenant/bankcard/nonBankNum')
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },
  // 设置模式
  setModel(enabled) {
    return httpFetch.post(`/api/tenant/bankcard/setBillEnable/CMBC/${enabled}`)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

  // 获取花呗开通的用户列表
  getUserOpenList(page, size) {
    return httpFetch.post(`/api/controlled/huabei/get/user/mappingList?page=${page}&size=${size}`);
  },

  // 获取公司开户配置a卡/银联
  getCardConfigList(params) {
    return httpFetch.get('/api/company/card/config', params);
  },

  // 更新a卡／银联的配置
  updateCardConfig(supplierCode, params) {
    return httpFetch.post(`/api/company/card/config?supplierCode=${supplierCode}`, params);
  },

  // 属性设置
  setCardBillEnable(cardBank, params) {
    return httpFetch.post(`/api/tenant/bankcard/setBillEnable/${cardBank}`, params)
      .catch((e) => {
        errorMessage(e.response);
        throw e;
      });
  },

};
